import 'package:flutter/material.dart';
import 'package:loan_market/confit/screen_adapter.dart';
import 'package:loan_market/pages/tabs/ShowList.dart';

class LoansPages extends StatefulWidget {
  @override
  _LoansPagesState createState() => _LoansPagesState();
}

class _LoansPagesState extends State<LoansPages>
    with SingleTickerProviderStateMixin {
  TabController controller;

  // @override
  // void initState() {
  //   super.initState();
  //   controller = TabController(length: 4, vsync: this);
  // }

  @override
  void initState() {
    controller = new TabController(
        vsync: this, //固定写法
        length: 4 //指定tab长度
        );
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    ScreenAdapter.init(context);
    return Scaffold(
      appBar: AppBar(
        automaticallyImplyLeading: false,
        elevation: 0.0,
        backgroundColor: Color(0xFF2F7BD9),
        brightness: Brightness.light,
        title: Text(
          'Pinjaman kariaku',
          textAlign: TextAlign.center,
          style: TextStyle(
            color: Color(0xFF333333),
            fontWeight: FontWeight.w500,
            fontSize: ScreenAdapter.size(40),
          ),
        ),
        bottom: PreferredSize(
          preferredSize: Size.fromHeight(68),
          child: Material(
            color: Color(0xFFFEF6E9),
            child: TabBar(
              indicatorColor: Color(0xFF666666),
              labelColor: Color(0xFF666666),
              unselectedLabelColor: Color(0xFF927759),
              indicatorSize: TabBarIndicatorSize.label,
              labelStyle: TextStyle(
                height: 1,
              ),
              controller: controller,
              tabs: <Widget>[
                Tab(
                  child: Container(
                    height: ScreenAdapter.height(130),
                    width: ScreenAdapter.width(130),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: <Widget>[
                        Image.asset('images/new.png', height: ScreenAdapter.height(64), width: ScreenAdapter.width(64), ),
                        Text('New', maxLines: 1, overflow: TextOverflow.ellipsis),// ada baru baru
                      ],
                    )
                  ),
                ),
                Tab(
                  child: Container(
                    height: ScreenAdapter.height(130),
                    width: ScreenAdapter.width(130),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: <Widget>[
                        Image.asset('images/rp.png', height: ScreenAdapter.height(64), width: ScreenAdapter.width(64), ),
                        Text('Besar', maxLines: 1, overflow: TextOverflow.ellipsis),// ada baru baru
                      ],
                    )
                  ),
                ),
                Tab(
                    child: Container(
                    height: ScreenAdapter.height(130),
                    width: ScreenAdapter.width(130),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: <Widget>[
                        Image.asset('images/interest.png', height: ScreenAdapter.height(64), width: ScreenAdapter.width(64), ),
                        Text('Rendah', maxLines: 1, overflow: TextOverflow.ellipsis),// ada baru baru
                      ],
                    )
                  ),
                ),
                Tab(
                  child: Container(
                    height: ScreenAdapter.height(130),
                    width: ScreenAdapter.width(130),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: <Widget>[
                        Image.asset('images/all.png', height: ScreenAdapter.height(64), width: ScreenAdapter.width(64), ),
                        Text('Semua', maxLines: 1, overflow: TextOverflow.ellipsis),// ada baru baru
                      ],
                    )
                  )
                ),
              ],
            ),
          ),
        )
        
      ),
      body: TabBarView(
        controller: controller,
        // children: _tables(),
        children: <Widget>[
          ShowListPage(arguments: {
            "id": 1
          },),
          ShowListPage(arguments: {
            "id": 2
          },),
          ShowListPage(arguments: {
            "id": 3
          },),
          ShowListPage(arguments: {
            "id": 4
          },),
        ],
      ),
    );
  }
}
